#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
	if(a%b==0)return b;
	else return gcd(b,a%b);
}

void solve(){
    ll a,b;
    cin>>a>>b;
    ll t=a*b/gcd(a,b);
    ll res=0;
    if(a!=t)res++;
    if(b!=t)res++;
    cout<<res<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}